<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
</html>
<script>
    // 81, 94, 11, 96, 12, 35, 17, 95, 28, 58, 41, 75, 15

// 使用希尔排序排序上面数字

// 希尔排序的实现

// function shellSort(arr) {
//     let len = arr.length;  //13

//     // 计算增量
//     let gap = Math.floor(len / 2);   // 6

//     while(gap > 0) {
//         for(let i = gap; i < len;i++) { //i=6 7 8 9
//             let j = i;    //j=6  7 8 9
//             let current = arr[i];  // current=17  95 28 58
    
//             // 插入排序的内层循环
//             while(j -gap >= 0 && arr[j-gap] > current) {
//                 arr[j] = arr[j-gap];
//                 j = j - gap;
//             }
//            arr[j] = current;
//         }
    
//         gap = Math.floor(gap / 2);
        
//     }
    
//     return arr
// }

let tempArr = [81, 94, 11, 96, 12, 35, 17, 95, 28, 58, 41, 75, 15];

// console.log(shellSort(tempArr));






function shellSort(arr) {
    let len = arr.length;

    //计算增量
    let gap = Math.floor(len/2);

    while(gap > 0) {
        for (let i = gap; i < len; i++) {
            let current = arr[i];
            let j = i;
            while(j - gap >= 0 && arr[j-gap] > current) {
                arr[j] = arr[j-gap];
                j = j - gap;
            }

            arr[j] = current;
        }

        gap = Math.floor(gap / 2);
    }

    return arr;
}

console.log(shellSort(tempArr))
</script>